<?php
/**
 * Each engineer has a duty to keep the code elegant
 * Created by wolffy.
 * Author @wolffy<13750088090@sina.cn>
 * Date: 2018/8/14
 * Time: 17:39
 */
namespace App\Http\Controllers\Api\V2_0_0;

use App\Http\Requests\Api\V2_0_0\CollectMoneyBillRequest;
use App\Http\Requests\Api\V2_0_0\RepaymentAccountWithdrawRequest;
use App\Services\AlipayValidateCardInfo\BankCardInfoService;
use App\Services\CollectMoneyService;
use App\Services\RepaymentAccountWithdrawService;
use Illuminate\Http\Request;

class CollectMoneyController extends BaseController
{
    protected $collectMoneyService;

    public function __construct(CollectMoneyService $collectMoneyService)
    {
        parent::__construct();
        $this->collectMoneyService = $collectMoneyService;
    }

    /**
     * 提现
     */
    public function withdraw(CollectMoneyBillRequest $request)
    {
        $passageId = (int)$request->passage_id;
        //还款通道是否存在
        if (!in_array($passageId, [2, 4])) {
            return $this->responseJson(10703);//收银通道不存在
        }
        return $this->collectMoneyService->withdraw($passageId, $this->user,
            $request->credit_card_id, $request->bank_card_id, $request->withdraw_money, $request->expire_date, $request->cvn2);
    }

    /**
     * 交易记录
     */
    public function tradeRecord(Request $request)
    {
        if (empty($request->credit_card_id)) {
            return $this->responseJson(422);
        }
        return $this->collectMoneyService->tradeRecord($this->user['user_id'], $request->credit_card_id);
    }

    /**
     * 交易明细
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function collectMoneyDetail(Request $request)
    {
        $status = json_decode($request->status);
        if (empty($status)) {
            return $this->responseJson(422);
        }
        return $this->collectMoneyService->getDetail($this->user['user_id'], $status, $request->page);
    }
}